#ifndef SYSTEM_LOGS_H
#define SYSTEM_LOGS_H

#include <QString>
#include <QDateTime>

enum class LogType : uint8_t {
    LOG_DEBUG = 1,    // 调试
    LOG_INFO = 2,     // 信息
    LOG_SUCCESS = 3,  // 成功
    LOG_WARNING = 4,  // 警告
    LOG_ERROR = 5     // 错误
};

// 信息类型枚举
enum class InfoType : uint8_t {
    SYSTEM = 1,           // 系统
    DATABASE = 2,         // 数据库
    DEVICE = 3,           // 设备
    CAMERA = 4,           // 相机
    IMAGE_PROCESSING = 5, // 图像处理
    PATH_PLANNING = 6,    // 路径规划
    COMMAND_EXEC = 7,     // 指令执行
    FIXTURE_CTRL = 8      // 夹具控制
};

struct LogRecord {
    QDateTime logTime;
    LogType logType;
    InfoType infoType;
    QString content;

    LogRecord() {
        logTime = QDateTime::currentDateTime();
    }

    LogRecord(LogType type, InfoType info, const QString& msg)
        : logType(type), infoType(info), content(msg) {
        logTime = QDateTime::currentDateTime();
    }

    // 转换为插入SQL
    QString toInsertSQL() const {
        return QString(
                   "INSERT INTO system_logs (log_time, log_type, info_type, content) "
                   "VALUES ('%1', %2, %3, '%4')"
                   ).arg(logTime.toString("yyyy-MM-dd hh:mm:ss.zzz"))
            .arg(static_cast<int>(logType))
            .arg(static_cast<int>(infoType))
            .arg(content);
    }

    // 获取日志类型字符串
    QString getLogTypeString() const {
        switch(logType) {
        case LogType::LOG_DEBUG: return "DEBUG";
        case LogType::LOG_INFO: return "INFO";
        case LogType::LOG_SUCCESS: return "SUCCESS";
        case LogType::LOG_WARNING: return "WARNING";
        case LogType::LOG_ERROR: return "ERROR";
        default: return "UNKNOWN";
        }
    }

    // 获取信息类型字符串
    QString getInfoTypeString() const {
        switch(infoType) {
        case InfoType::SYSTEM: return "系统";
        case InfoType::DATABASE: return "数据库";
        case InfoType::DEVICE: return "设备";
        case InfoType::CAMERA: return "相机";
        case InfoType::IMAGE_PROCESSING: return "图像处理";
        case InfoType::PATH_PLANNING: return "路径规划";
        case InfoType::COMMAND_EXEC: return "指令执行";
        case InfoType::FIXTURE_CTRL: return "夹具控制";
        default: return "未知";
        }
    }
};

#endif // SYSTEM_LOGS_H
